/**
 * calculate.js
 */

var a,b,c,sign_a,sign_b,summary;
var ra = require('./random-a');
var rb = require('./random-b');
var rc = require('./random-c');
var sign = require('./sign');
console.log('Calculate start!');

/**
 * @type{exports}
 */
var readline = require('readline');
rl = readline.createInterface({
    input : process.stdin,
    output : process.stdout
});
rl.setPrompt('Calculate');
rl.prompt();
a = ra.generate_a();
b = rb.generate_b();
c = rc.generate_c();
sign_a = sign.generate_sign_a();
sign_b = sign.generate_sign_b();
summary = cal(a,b,c,sign_a,sign_b);

rl.on('line',function(line){
    if(line.trim() == summary){
        console.info("answer is right!!!");
    }else{
        console.info("answer is error!! The correct answer is " + summary +".");
    }
    rl.prompt();

    a = ra.generate_a();
    b = rb.generate_b();
    c = rc.generate_c();
    sign_a = sign.generate_sign_a();
    sign_b = sign.generate_sign_b();
    summary = cal(a,b,c,sign_a,sign_b);
}).on('close',function(){
    console.log("Calculate exits!!!");
    process.exit();
})



/**
 * 四则运算方法 -cal()
 * @param a
 * @param b
 * @param sign 运算符
 * @returns {*}
 */

function cal(stra,strb,strc,signa,signb){
    var s = "";
    var result = 0;
    s = stra+signa+strb+signb+strc;
    console.log(s);
    result = eval(s);
    return result;
}